import JSEncrypt from 'jsencrypt/bin/jsencrypt';

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXrZQnkFGUTFi2KqYFWk9u6IiTTCsf4cstid+KaQXNxue7dHXgv3d5/Q3AeFotLYUNZq1CDzax01xGTLcjHVc2ku2krrbpm5U3fu7XwlH4Za9oosc+f7AYlxeTSBPVHG3IBwwZbVP8HAgc9LSWDOxQanA6PAK2ldH9QEBLaGKl+QIDAQAB';

const privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJetlCeQUZRMWLYqpgVaT27oiJNMKx/hyy2J34ppBc3G57t0deC/d3n9DcB4Wi0thQ1mrUIPNrHTXEZMtyMdVzaS7aSutumblTd+7tfCUfhlr2iixz5/sBiXF5NIE9UcbcgHDBltU/wcCBz0tJYM7FBqcDo8AraV0f1AQEtoYqX5AgMBAAECgYAMb2mvGLDnhJ7dSH/V/oJ2qE/SK7N5aKycrioKkfOs3DrRbonfhDMKaEnBVtylyY6X+6wGt3KXf6mYBeAZ2+TzbqYqLiV4I9np6emNqzcq61A/zeozaQie+pktxxukECXFZnblr0kayZjBppWnlMOzAq0mfwW+nQLeCuYQh7r1pQJBAOr/hWg6DvJsXDE9aJVdg274bgdMu0CJ7z70kbdSzZN+Fi3ICYt2Lts3AufvTeVJdv+VAHlPk1mR9c/5k4vIJ68CQQClO8rtgJrAsaiRtXTbQBybFYzGvZUOEpQbklYHCcazA+sDIdhqAAIC2f/sf/9I4SIC7v2HOf389Cy1Z6smbk7XAkEAi9q0L5pV6OqaV2efhT0ZCoLpIIkG69rrOoFc80hhNkUUt/xTyd709dugbB4cMrftDSBFHu0/2U+nhjWXHNpq2wJBAIGO56fgTfdHljBiAnWjyIpFlHOE1WoKYT1ZOcEdBkL5kH2NPT6oMOuBea08E7RWaq+4KuysKR39a0z2M3nXxlMCQDkc0CUqPahXXXXqe/t69LC6IfevU9TQs5SSAm0bwnD3BGjt9RY9+Y6DxY0MWYGrxl/emMMWyNUx2cK8Z8KY57s=';

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey);
  return encryptor.decrypt(txt);
}

